#ifndef __BSP_GPIO_H__
#define __BSP_GPIO_H__


#include "hc32_ll.h"
#include "hc32_ll_gpio.h"


typedef enum en_port_func
{
    Func_Gpio       = 0u,               ///< function set to gpio
    Func_Fcmref     = 1u,               ///< function set to fcm reference
    Func_Rtcout     = 1u,               ///< function set to rtc output
    Func_Vcout      = 1u,               ///< function set to vc output
    Func_Adtrg      = 1u,               ///< function set to adc trigger
    Func_Mclkout    = 1u,               ///< function set to mclk output
    Func_Tim4       = 2u,               ///< function set to timer4
    Func_Tim6       = 3u,               ///< function set to timer6
    Func_Tima0      = 4u,               ///< function set to timerA
    Func_Tima1      = 5u,               ///< function set to timerA
    Func_Tima2      = 6u,               ///< function set to timerA
    Func_Emb        = 6u,               ///< function set to emb
    Func_Usart_Ck   = 7u,               ///< function set to usart clk
    Func_Spi_Nss    = 7u,               ///< function set to spi nss
    Func_Qspi       = 7u,               ///< function set to qspi
    Func_Key        = 8u,               ///< function set to key
    Func_Sdio       = 9u,               ///< function set to sdio
    Func_I2s        = 10u,              ///< function set to i2s
    Func_UsbF       = 10u,              ///< function set to usb full speed
    Func_Evnpt      = 14u,              ///< function set to event port
    Func_Eventout   = 15u,              ///< function set to event out
    Func_Usart1_Tx  = 32u,              ///< function set to usart tx of ch.1
    Func_Usart3_Tx  = 32u,              ///< function set to usart tx of ch.3
    Func_Usart1_Rx  = 33u,              ///< function set to usart rx of ch.1
    Func_Usart3_Rx  = 33u,              ///< function set to usart rx of ch.3
    Func_Usart1_Rts = 34u,              ///< function set to usart rts of ch.1
    Func_Usart3_Rts = 34u,              ///< function set to usart rts of ch.3
    Func_Usart1_Cts = 35u,              ///< function set to usart cts of ch.1
    Func_Usart3_Cts = 35u,              ///< function set to usart cts of ch.3
    Func_Usart2_Tx  = 36u,              ///< function set to usart tx of ch.2
    Func_Usart4_Tx  = 36u,              ///< function set to usart tx of ch.4
    Func_Usart2_Rx  = 37u,              ///< function set to usart rx of ch.2
    Func_Usart4_Rx  = 37u,              ///< function set to usart rx of ch.4
    Func_Usart2_Rts = 38u,              ///< function set to usart rts of ch.2
    Func_Usart4_Rts = 38u,              ///< function set to usart rts of ch.4
    Func_Usart2_Cts = 39u,              ///< function set to usart cts of ch.2
    Func_Usart4_Cts = 39u,              ///< function set to usart cts of ch.4
    Func_Spi1_Mosi  = 40u,              ///< function set to spi mosi of ch.1
    Func_Spi3_Mosi  = 40u,              ///< function set to spi mosi of ch.3
    Func_Spi1_Miso  = 41u,              ///< function set to spi miso of ch.1
    Func_Spi3_Miso  = 41u,              ///< function set to spi miso of ch.3
    Func_Spi1_Nss0  = 42u,              ///< function set to spi nss0 of ch.1
    Func_Spi3_Nss0  = 42u,              ///< function set to spi nss0 of ch.3
    Func_Spi1_Sck   = 43u,              ///< function set to spi sck of ch.1
    Func_Spi3_Sck   = 43u,              ///< function set to spi sck of ch.3
    Func_Spi2_Mosi  = 44u,              ///< function set to spi mosi of ch.2
    Func_Spi4_Mosi  = 44u,              ///< function set to spi mosi of ch.2
    Func_Spi2_Miso  = 45u,              ///< function set to spi miso of ch.4
    Func_Spi4_Miso  = 45u,              ///< function set to spi miso of ch.4
    Func_Spi2_Nss0  = 46u,              ///< function set to spi nss0 of ch.2
    Func_Spi4_Nss0  = 46u,              ///< function set to spi nss0 of ch.4
    Func_Spi2_Sck   = 47u,              ///< function set to spi sck of ch.2
    Func_Spi4_Sck   = 47u,              ///< function set to spi sck of ch.4
    Func_I2c1_Sda   = 48u,              ///< function set to i2c sda of ch.1
    Func_I2c3_Sda   = 48u,              ///< function set to i2c sda of ch.3
    Func_I2c1_Scl   = 49u,              ///< function set to i2c scl of ch.1
    Func_I2c3_Scl   = 49u,              ///< function set to i2c scl of ch.3
    Func_I2c2_Sda   = 50u,              ///< function set to i2c sda of ch.2
    Func_Can1_Tx    = 50u,              ///< function set to can tx of ch.1
    Func_I2c2_Scl   = 51u,              ///< function set to i2c scl of ch.2
    Func_Can1_Rx    = 51u,              ///< function set to can rx of ch.1
    Func_I2s1_Sd    = 52u,              ///< function set to i2s sd of ch.1
    Func_I2s3_Sd    = 52u,              ///< function set to i2s sd of ch.3
    Func_I2s1_Sdin  = 53u,              ///< function set to i2s sdin of ch.1
    Func_I2s3_Sdin  = 53u,              ///< function set to i2s sdin of ch.3
    Func_I2s1_Ws    = 54u,              ///< function set to i2s ws of ch.1
    Func_I2s3_Ws    = 54u,              ///< function set to i2s ws of ch.3
    Func_I2s1_Ck    = 55u,              ///< function set to i2s ck of ch.1
    Func_I2s3_Ck    = 55u,              ///< function set to i2s ck of ch.3
    Func_I2s2_Sd    = 56u,              ///< function set to i2s sd of ch.2
    Func_I2s4_Sd    = 56u,              ///< function set to i2s sd of ch.4
    Func_I2s2_Sdin  = 57u,              ///< function set to i2s sdin of ch.2
    Func_I2s4_Sdin  = 57u,              ///< function set to i2s sdin of ch.4
    Func_I2s2_Ws    = 58u,              ///< function set to i2s ws of ch.2
    Func_I2s4_Ws    = 58u,              ///< function set to i2s ws of ch.4
    Func_I2s2_Ck    = 59u,              ///< function set to i2s ck of ch.2
    Func_I2s4_Ck    = 59u,              ///< function set to i2s ck of ch.4
}en_port_func_t;


#define OUT1_PORT 		 	GPIO_PORT_A
#define OUT1_PIN  			GPIO_PIN_02

#define OUT2_PORT 		 	GPIO_PORT_A
#define OUT2_PIN  			GPIO_PIN_01

#define OUT3_PORT 		 	GPIO_PORT_A
#define OUT3_PIN  			GPIO_PIN_00

#define OUT4_PORT  		 	GPIO_PORT_C
#define OUT4_PIN  			GPIO_PIN_03

#define OUT5_PORT           GPIO_PORT_C
#define OUT5_PIN            GPIO_PIN_13

#define OUT6_PORT           GPIO_PORT_C
#define OUT6_PIN            GPIO_PIN_02


#define OUT7_PORT           GPIO_PORT_B
#define OUT7_PIN            GPIO_PIN_09


#define IN1_PORT			GPIO_PORT_A			
#define IN1_PIN				GPIO_PIN_03	

#define IN2_PORT			GPIO_PORT_A			
#define IN2_PIN				GPIO_PIN_04

#define IN3_PORT			GPIO_PORT_A			
#define IN3_PIN				GPIO_PIN_05

#define IN4_PORT			GPIO_PORT_A			
#define IN4_PIN				GPIO_PIN_06

#define IN5_PORT			GPIO_PORT_A			
#define IN5_PIN				GPIO_PIN_07

#define IN6_PORT			GPIO_PORT_C			
#define IN6_PIN				GPIO_PIN_04

#define IN7_PORT            GPIO_PORT_B
#define IN7_PIN             GPIO_PIN_01

#define IN8_PORT            GPIO_PORT_B
#define IN8_PIN             GPIO_PIN_02


#define VALVE1_A_PORT  		GPIO_PORT_B
#define VALVE1_A_PIN  		GPIO_PIN_14

#define VALVE1_B_PORT  		GPIO_PORT_B
#define VALVE1_B_PIN  		GPIO_PIN_15

#define VALVE2_A_PORT 	 	GPIO_PORT_C
#define VALVE2_A_PIN  		GPIO_PIN_06

#define VALVE2_B_PORT 		GPIO_PORT_C
#define VALVE2_B_PIN  		GPIO_PIN_07

#define LED_PORT			GPIO_PORT_A
#define LED_PIN       		GPIO_PIN_12

#define WATER_FLOW_SW1_PORT	GPIO_PORT_C
#define WATER_FLOW_SW1_PIN  GPIO_PIN_08

#define WATER_FLOW_SW2_PORT	GPIO_PORT_C
#define WATER_FLOW_SW2_PIN  GPIO_PIN_09


#define DI1 GPIO_ReadInputPins(GPIO_PORT_A,GPIO_PIN_03)
#define DI2 GPIO_ReadInputPins(GPIO_PORT_A,GPIO_PIN_04)
#define DI3 GPIO_ReadInputPins(GPIO_PORT_A,GPIO_PIN_05)
#define DI4 GPIO_ReadInputPins(GPIO_PORT_A,GPIO_PIN_06)
#define DI5 GPIO_ReadInputPins(GPIO_PORT_A,GPIO_PIN_07)
#define DI6 GPIO_ReadInputPins(GPIO_PORT_C,GPIO_PIN_04)
#define DI7 GPIO_ReadInputPins(GPIO_PORT_B, GPIO_PIN_01)
#define DI8 GPIO_ReadInputPins(GPIO_PORT_B, GPIO_PIN_02)
#define DI9 GPIO_ReadInputPins(GPIO_PORT_B, GPIO_PIN_10)

#define WFS_DI1 GPIO_ReadInputPins(GPIO_PORT_C, GPIO_PIN_08)
#define WFS_DI2 GPIO_ReadInputPins(GPIO_PORT_C, GPIO_PIN_09)

#define I_V1_PORT            GPIO_PORT_C
#define I_V1_PIN             GPIO_PIN_14

#define I_V2_PORT            GPIO_PORT_C
#define I_V2_PIN             GPIO_PIN_15


extern uint8_t Func_Write_VALVE ;

//typedef struct {
//uint8_t Calc;
//uint8_t Coil_Number [128];
//uint8_t Coil_Data [128];
//}Coil_Sync_ ;
//extern Coil_Sync_     Coil_Sync;


int valve_sample(void);
void BSP_GPIO_Config(void);
void BSP_Sync_coil_State(void);
void BSP_Sync_input_register_State(void);
int timer3_init(void);

#endif
